package com.yami.shop.admin.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.Comment;
import com.yami.shop.bean.model.Post;
import com.yami.shop.bean.param.PostsQuery;
import com.yami.shop.bean.vo.CommentVO;
import com.yami.shop.bean.vo.PostsVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.CommentService;
import org.apache.poi.xssf.model.Comments;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("/social/comment")
public class CommentsController {

    @Autowired
    private CommentService commentsService;

    /**
     * 分页查询评论
     * @return
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('social:comments:page')")
    public ServerResponseEntity<IPage<CommentVO>> page(PostsQuery query, PageParam<Comment> page) {

        return ServerResponseEntity.success(commentsService.getPostPage(page, query));
    }

    /**
     * 删除评论
     */
    @DeleteMapping("/{commentIds}")
    @PreAuthorize("@pms.hasPermission('social:comments:delete')")
    public ServerResponseEntity<Void> delete(@PathVariable Long[] commentIds) {
        commentsService.removeBatchByIds(Arrays.asList(commentIds));
        return ServerResponseEntity.success();
    }
}
